#!/user/bin/env node

const http = require('http'),
      log = console.log,
      fs = require('fs');

http.createServer((req,res)=>{
  log(`${req.method}${req.url}HTTP/${req.httpVersion}`);
  log(req.heqders);
  log('');

  let file = __dirname + req.url;

  let s = fs.createReadStream(file);
  s.on('error',(err)=>{
    console.log(err.message);
    res.statusCode = 404;
    res.end(err.message);
    log('faile')
  });
  s.pipe(res);
  console.log('success');
}).listen(8080);
